package com.im.common.util;

import com.im.common.constant.Constant;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

/**
 * 生成id工具
 *
 * @author yunZhouJiaDi
 */
public class GenerateIdUtil {

    public static String generateUserId() {
        SimpleDateFormat format = new SimpleDateFormat("HHmmssSSS");
        String dateStr = format.format(new Date());
        return Constant.SystemConstant.USER_PREFIX.concat(dateStr);
    }

    public static String generateUserChatId(String[] userIds) {
        Arrays.sort(userIds);
        return DigestUtils.md5Hex(StringUtils.join(userIds, ""));
    }

    public static String generateMessageId() {
        Date createDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
        String messageId = sdf.format(createDate);
        return messageId;
    }

    public static String generateClusterId() {
        SimpleDateFormat format = new SimpleDateFormat("HHmmssSSS");
        String dateStr = format.format(new Date());
        return Constant.SystemConstant.CLUSTER_PREFIX.concat(dateStr);
    }

    public static final String generateClusterChatId(String clusterId) {
        return DigestUtils.md5Hex(clusterId);
    }

}
